/**
 * @author lulongwen
 * Date: 2023-08-30 22:38
 * Description: Triangle，三角形
 */

import { number, bool } from 'prop-types';

Triangle.propTypes = {
  width: number,
  height: number,
  readOnly: bool,
};
Triangle.defaultProps = {
  width: 24,
  height: 24,
  readOnly: false,
}

export function Triangle(props) {
  const { width, height, selected, readOnly } = props;

  const cx = width / 2;

  // 'M0,70 L50,0 L100,70 z'
  const path = [
    ['M0', height], // M0,70
    [`L${cx}`, 0], // L50,0
    [`L${width}`, height], // L100,70
    ['z'],
  ]
    .map(item => item.join(','))
    .join(' ');

  return (
    <svg
      xmlns='http://www.w3.org/2000/svg'
      width={width}
      height={height}
      className={readOnly ? 'overflow-visible' : 'overflow-hidden'}
    >
      <path
        d={path}
        // d='M0,70 L50,0 L100,70 z'
        fill='#ff6700'
        strokeWidth={selected && readOnly ? 2 : 0}
        stroke='#fff'
      />
    </svg>
  );
}
